(() => {
	let ele = {};

	ele.Balance = $('#balance');
	ele.withdrawal = $('#withdrawal');
	ele.toGetone = $('#toGetone');

	ele.getnum = $('#getnum');//可提次数


	let alipay_name = getCookie('alipay_name');
	let alipay_account = getCookie('alipay_account');
	ele.isshow = document.getElementById('isshow')

	ele.collect = $('#collect')
	ele.zhihao = $('#zhihao')
	if (alipay_name != 'null' && alipay_name != '') {
		ele.isshow.style.display = 'none'
		ele.collect.style.display = 'block'
		ele.zhihao.innerHTML = alipay_account
	} else {
		ele.isshow.style.display = 'block'
		ele.collect.style.display = 'none'
	}

	let balance = parseFloat(getCookie('money')) || '0.00';

	init();

	function init() {
		getUserInfo(res => {
			balance = res.user_money;
			ele.Balance.innerText = res.user_money;
			ele.getnum.innerHTML = res.withdraw_chance


			// 一米提现
			ele.toGetone.onclick = () => {
				if (res.withdraw_chance == 0) {
					openTips('请先获取次数')
					return
				} else {
					if (res.user_money == 0) {
						openTips('余额不足,不能提现')
						return
					}
					sendWithdrawal(1)
				}
			}
		});
	}

	// 提现
	let idi = 0
	// 点击选择价格
	let yuer = document.querySelectorAll('.approve')
	for (let i = 0; i < yuer.length; i++) {
		yuer[i].onclick = () => {
			idi = i
			for (var j = 0; j < yuer.length; j++) {
				yuer[j].classList = 'approve'
			}
			yuer[i].classList = "approve active"
		}
	}

	// 点击提现
	ele.withdrawal.onclick = () => {
		let arr = [20, 100, 500, 1000, 3000]
		let amount = 0;
		amount = arr[idi]
		if (amount > parseFloat(balance)) {
			openTips('余额不足,不能提现')
		}
		else {
			sendWithdrawal(amount);
		}
	}


	// 发送提现请求
	function sendWithdrawal(amount) {
		let token = getCookie('token');
		let userid = getCookie('userid');
		ajax({
			url: API_PATH.CASH,
			method: 'POST',
			header: {
				Authorization: token
			},
			data: {
				type: 1,
				money: amount,
			},
			success: res => {
				if (res.code == 1) {
					ele.getnum.innerHTML = res.data.withdraw_chance
					ele.Balance.innerText = res.data.wallet.after_money
				}
				openTips(res.msg);
			}
		});
	}


})();
